package com.atguigu.servlet;

import jakarta.servlet.Servlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/s1")
public class UserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接受请求参数
        String username = req.getParameter("username");
        //2.处理业务代码
        String info="NO";
        int status=404;
        if ("admin".equals(username)){
            //设置状态码描述
           info="yes";
           status=200;
        }
        //3.设置响应体,会自动响应
        resp.setStatus(status);
        //获取响应流,响应的字符流
        resp.setHeader("Context-Type","text/html");
        PrintWriter writer = resp.getWriter();
        writer.write(info);
    }
}
